import { Component, OnInit,Input } from '@angular/core';
import { Driver } from '../driver';

import { ActivatedRoute, Params } from '@angular/router';
import { DriverService } from '../driver.service';

@Component({
    selector: 'driver-detail',
    templateUrl: './driver-detail.component.html',
    // styleUrls: ['./driver-detail.component.css']
})

export class DriverDetailComponent implements OnInit {
    @Input()
    driver: Driver;

    constructor(
        private driverService: DriverService,
        private router: ActivatedRoute) {

    }

    ngOnInit() {
        this.router.params.forEach((params: Params) => {
            let driver_id = +params['driver_id'];
            this.driverService.getDriver(driver_id).then(driver => this.driver = driver);
        });
    }

    goBack() {
        window.history.back();
    }

    save(): void {
        this.driverService.save(this.driver).then(() => this.goBack());
    }

}